package com.yuntsg.ruiijn.databse_search;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author: i2twmx@gmail.com
 * @date: 2018-12-16.
 * @Description:
 */
public abstract class BaseService<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IService<T> {

    @Autowired
    private M m;


    public M getMapper() {
        return m;
    }


    public boolean removeboolean(boolean b, Wrapper<T> wrapper) {
        if (b) {
            return super.remove(wrapper);
        }
        return true;
    }

    @Override
    public List<T> listByIds(Collection<? extends Serializable> idList) {

        Collection<T> ts = super.listByIds(idList);
        return toList(ts);
    }

    private List<T> toList(Collection<T> ts) {
        if (ts instanceof List) {
            return (List) ts;
        } else {
            return new ArrayList(ts);
        }
    }

}
